package com.example.userservice.Controller;

import com.example.common.domain.Result;
import com.example.common.domain.pojo.Student;
import com.example.common.domain.pojo.Teacher;
import com.example.common.domain.pojo.User;
import com.example.common.utils.MD5Util;
import com.example.userservice.domain.vo.UserTokenVo;
import com.example.userservice.service.AuthService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Api(value = "安全接口", description = "权限")
@RestController
@RefreshScope//时时刷新配置信息
@Slf4j  //日志  log.info("登录日志测试：");
@RequestMapping("/auth")
public class AuthController {

    @Autowired
    private AuthService authService;

    /**
     * 主动刷新Token
     * @param id
     * @return
     */
    @PostMapping("/refreshToken")  // 刷新 Token
    public Result<UserTokenVo> refreshToken(String id) {
        System.out.println("进入refreshToken方法：");
        log.info("登录日志测试：");
        User us=authService.getUserById(id);
        Map<String, String> toKenMap=authService.AddToken(String.valueOf(us.getId()), us.getRole().getDesc());//保存token
        UserTokenVo userTokenVo=new UserTokenVo(us,toKenMap,null,null);
        return Result.success(userTokenVo);
    }


}
